#region License

// Copyright (c) 2008, BXO Solutions AB
// All rights reserved.
// 
// Redistribution and use in source and binary forms, with or without 
// modification, are permitted provided that the following conditions are met:
// 
//     * Redistributions of source code must retain the above copyright notice, 
//       this list of conditions and the following disclaimer.
//     * Redistributions in binary form must reproduce the above copyright 
//       notice, this list of conditions and the following disclaimer in the 
//       documentation and/or other materials provided with the distribution.
//     * Neither the name of the BXO Solutions AB nor the names of its 
//       contributors may be used to endorse or promote products derived from 
//       this software without specific prior written permission.
// 
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 
// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 
// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

#endregion

using System;
using Castle.ActiveRecord;

namespace Bxo.TestingPortal.Entities {
    /// <summary>
    /// Represents details of particular version of test scenario.
    /// </summary>
    [ActiveRecord]
    public class ScenarioVersion {
        private DateTime creationDateTime;

        private string instruction;

        private Scenario scenario;

        private string summary;

        /// <summary>
        /// Initializes a new instance of the <see cref="ScenarioVersion"/> class
        /// with the specified summary and instruction.
        /// </summary>
        /// <param name="summary">Short (preferably one sentence long) text describing the scenario.</param>
        /// <param name="instruction">Text describing how to execute the test represented by the scenario.</param>
        /// <exception cref="ArgumentNullException"><paramref name="summary"/> or <paramref name="instruction"/> is <see langword="null"/>.</exception>
        /// <exception cref="ArgumentException"><paramref name="summary"/> is an empty string.</exception>
        public ScenarioVersion(string summary, string instruction) {
            if (summary == null) {
                throw new ArgumentNullException("summary");
            }
            if (summary.Length == 0) {
                throw new ArgumentException("Summary cannot be empty.", "summary");
            }
            if (instruction == null) {
                throw new ArgumentNullException("instruction");
            }

            this.summary = summary;
            this.instruction = instruction;
            this.creationDateTime = DateTime.Now;
        }

        protected ScenarioVersion() {
        }

        /// <summary>
        /// This member is provided only to satisfy NHibernate requirements and should not be used
        /// by user code.
        /// </summary>
        [PrimaryKey]
        public virtual int Id { get; set; }

        /// <summary>
        /// Gets the short description for the scenario.
        /// </summary>
        /// <value>
        /// Short (preferably one sentence long) text describing the scenario.
        /// </value>
        [Property(Access = PropertyAccess.FieldCamelcase)]
        public virtual string Summary {
            get { return this.summary; }
        }

        /// <summary>
        /// Gets the long and detailed description on how to perform the test.
        /// </summary>
        /// <value>
        /// Text describing how to execute the test represented by the scenario.
        /// </value>
        [Property(Access = PropertyAccess.FieldCamelcase)]
        public virtual string Instruction {
            get { return this.instruction; }
        }

        [BelongsTo(Cascade = CascadeEnum.SaveUpdate)]
        public virtual Scenario Scenario {
            get { return this.scenario; }
            internal set { this.scenario = value; }
        }

        [Property(Access = PropertyAccess.FieldCamelcase)]
        public virtual DateTime CreationDateTime {
            get { return this.creationDateTime; }
        }
    }
}